package com.hundsun.yr.universal.p2p.ui.view;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hundsun.mobile.zwgt.R;



/**
 * @Title: LoanDateItem.java 
 * @Description: 借款明细事件Item
 * @date 2016-1-7 上午10:49:06 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class LoanDateItem extends LinearLayout {
	
	/**上半部分竖线**/
	private View line_top=null;
	/**下半部分竖线**/
	private View line_bottom=null;
	/**时间轴**/
	private ImageView iv_timeline=null;
	/**主标题**/
	private TextView tv_title=null;
	/**副标题**/
	private TextView tv_subTitle=null;
	/**是否顶部**/
	private boolean isTop=false;
	/**是否底部**/
	private boolean isBottom=false;
	/**是否时间轴刚好走到这个节点**/
	private boolean isCheck=false;
	/**是否时间轴走过这个节点**/
	private boolean isWalk=false;
	/**时间轴颜色**/
	private int timeline=0;
	/**默认时间轴颜色**/
	private int line=0;
	/**时间轴icon**/
	private Drawable icon=null;
	/**时间轴默认icon**/
	private Drawable deficon=null;
	
	/**时间轴选中时icon**/
	private Drawable checkIcon=null;
	/**时间轴title**/
	private String title="";
	/**时间轴subTitle**/
	private String subtitle="";
	
	/**
	 * 时间轴类型
	 * @Title: LoanDateItem.java 
	 * @Description: TODO(用一句话描述该文件做什么) 
	 * @date 2016-1-7 下午2:39:14 
	 * @author:hejun.shen
	 * @email:shenhj15971@hundsun.com 
	 * @replace author:
	 * @replace date:
	 * @version V1.0
	 */
	public static enum TimeLineType {
		NONE,//无状态
		WALK,//已经走过世间
		CHECK;//时间走到这里
		
		public static TimeLineType none = TimeLineType.NONE;
		public static TimeLineType getDefaultType() {
			return none;
		}
		
	}
	private TimeLineType mode=TimeLineType.getDefaultType();
	
	/**
	 * 设置状态
	 */
	@SuppressWarnings("deprecation")
	public void setMode(TimeLineType mode){
		
		
		switch (mode) {
		case NONE:
			line_top.setBackgroundColor(line);
			line_bottom.setBackgroundColor(line);
			if(deficon!=null){
				iv_timeline.setBackgroundDrawable(deficon);
			}
			break;
			
		case WALK:
			line_top.setBackgroundColor(timeline);
			line_bottom.setBackgroundColor(timeline);
			if(icon!=null){
				iv_timeline.setBackgroundDrawable(icon);
			}
			
			break;
			
		case CHECK:
			
			line_top.setBackgroundColor(timeline);
			line_bottom.setBackgroundColor(line);
			if(checkIcon!=null){
				iv_timeline.setBackgroundDrawable(checkIcon);
			}
			break;
			
		default:
			break;
		}
		
		invalidate();
	}
	
	/**
	 * 是否为顶部
	 * @param isTop
	 */
	public void setIsTop(boolean isTop){
		if(isTop)line_top.setVisibility(View.INVISIBLE);
	}
	/**
	 * 是否为顶部
	 * @param isBottom
	 */
	public void setIsBottom(boolean isBottom){
		if(isBottom)line_bottom.setVisibility(View.INVISIBLE);
	}
	
	public LoanDateItem(Context context) {
		this(context, null);
		// TODO Auto-generated constructor stub
	}
	
	public LoanDateItem(Context context, AttributeSet attrs) {
		this(context, attrs,0);
		// TODO Auto-generated constructor stub
	}
	public LoanDateItem(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
		
		
		init(context, attrs);
	}
	
	@SuppressWarnings("deprecation")
	private void init(Context context, AttributeSet attrs){
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.view_loan_item, this, true);
		line_top=(View)findViewById(R.id.line_top);
		line_bottom=(View)findViewById(R.id.line_bottom);
		iv_timeline=(ImageView)findViewById(R.id.iv_timeline);
		tv_title=(TextView)findViewById(R.id.tv_title);
		tv_subTitle=(TextView)findViewById(R.id.tv_subtitle);
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LoanDateItem);
		
		isTop=a.getBoolean(R.styleable.LoanDateItem_li_istop, false);
		line_top.setVisibility(isTop?View.INVISIBLE:View.VISIBLE);
		isBottom=a.getBoolean(R.styleable.LoanDateItem_li_isbottom, false);
		line_bottom.setVisibility(isBottom?View.INVISIBLE:View.VISIBLE);
		
		isWalk=a.getBoolean(R.styleable.LoanDateItem_li_iswalk, false);
		icon=getResources().getDrawable(R.drawable.icon_pasttime);
		deficon=getResources().getDrawable(R.drawable.icon_futuretime);
		checkIcon=getResources().getDrawable(R.drawable.icon_nowtime);
		
		line=a.getColor(R.styleable.LoanDateItem_li_line, context.getResources().getColor(R.color.home_progress_cl));
		timeline=a.getColor(R.styleable.LoanDateItem_li_timeline, context.getResources().getColor(R.color.loan_timeline));
		
		if (a.hasValue(R.styleable.LoanDateItem_li_icon)) {
			icon=a.getDrawable(R.styleable.LoanDateItem_li_icon);
			
		}
		if (a.hasValue(R.styleable.LoanDateItem_li_deficon)) {
			deficon=a.getDrawable(R.styleable.LoanDateItem_li_deficon);
		}
		
		if (a.hasValue(R.styleable.LoanDateItem_li_checkicon)) {
			checkIcon=a.getDrawable(R.styleable.LoanDateItem_li_checkicon);
		}
		
		if (a.hasValue(R.styleable.LoanDateItem_li_ischeck)) {
			isCheck=a.getBoolean(R.styleable.LoanDateItem_li_ischeck, false);
			
		}
		
		if(isWalk){
			line_top.setBackgroundColor(timeline);
			line_bottom.setBackgroundColor(timeline);
			if(icon!=null){
				iv_timeline.setBackgroundDrawable(icon);
			}
		}else {
			if(isCheck){
				line_top.setBackgroundColor(timeline);
				line_bottom.setBackgroundColor(line);
				if(isCheck&&checkIcon!=null){
					iv_timeline.setBackgroundDrawable(checkIcon);
				}
			}else{
				line_top.setBackgroundColor(line);
				line_bottom.setBackgroundColor(line);
				if(deficon!=null){
					iv_timeline.setBackgroundDrawable(deficon);
				}
			}
		}
//		line_top.setBackgroundColor(top);
//		line_bottom.setBackgroundColor(bottom);
		
		
		if (a.hasValue(R.styleable.LoanDateItem_li_title)) {
			title=a.getString(R.styleable.LoanDateItem_li_title);
			tv_title.setText(title);
		}
		
		if (a.hasValue(R.styleable.LoanDateItem_li_subtitle)) {
			subtitle=a.getString(R.styleable.LoanDateItem_li_subtitle);
			tv_subTitle.setText(subtitle);
		}
    	a.recycle();
	}
	
	
	/**
	 * 设置标题
	 * @param title
	 */
	public void setTitle(String title){
		tv_title.setText(title);
	}
	
	
	
	/**
	 * 设置副标题
	 * @param subTitle
	 */
	public void setSubTitle(String subTitle){
		tv_subTitle.setText(subTitle);
	}
	
	/**
	 * 设置TopLine颜色
	 * @param color
	 */
	public void setTopLine(int color){
		line_top.setBackgroundColor(color);
	}
	
	/**
	 * 设置TopLine颜色
	 * @param drawable
	 */
	@SuppressWarnings("deprecation")
	public void setTopLine(Drawable drawable){
		line_top.setBackgroundDrawable(drawable);
	}
	
	/**
	 * 设置BottomLine颜色
	 * @param color
	 */
	public void setBottomLine(int color){
		line_bottom.setBackgroundColor(color);
	}
	
	/**
	 * 设置BottomLine颜色
	 * @param drawable
	 */
	@SuppressWarnings("deprecation")
	public void setBottomLine(Drawable drawable){
		line_bottom.setBackgroundDrawable(drawable);
	}
	
	/**
	 * 设置TimeLine背景
	 * @param color
	 */
	@SuppressWarnings("deprecation")
	public void setTimeLine(Drawable drawable){
		iv_timeline.setBackgroundDrawable(drawable);
	}
	
	/**
	 * 设置TimeLine背景
	 * @param color
	 */
	public void setTimeLineRes(int res){
		iv_timeline.setBackgroundResource(res);
	}
	
	

}
